/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Description: GPU/NPU send/recv typical mr manager
 */

#ifndef HCCL_TYPICAL_MR_MANAGER_H
#define HCCL_TYPICAL_MR_MANAGER_H

#include <mutex>
#include <map>
#include "hccl_common.h"
#include "network/hccp.h"

namespace hccl {
class TypicalMrManager {
public:
    static constexpr uint32_t DEFAULT_MR_KEY = 0;

    static TypicalMrManager &GetInstance();
    HcclResult RegisterMem(struct mr_info &mrInfo);                  // register MR
    HcclResult DeRegisterMem(struct mr_info &mrInfo);                // unregister MR

private:
    TypicalMrManager();
    ~TypicalMrManager();
    // Delete copy and move constructors and assign operators
    TypicalMrManager(TypicalMrManager const&) = delete;             // Copy construct
    TypicalMrManager(TypicalMrManager&&) = delete;                  // Move construct
    TypicalMrManager& operator=(TypicalMrManager const&) = delete;  // Copy assign
    TypicalMrManager& operator=(TypicalMrManager &&) = delete;      // Move assign

    HcclResult ReleaseMrResource();

    RdmaHandle rdmaHandle_ = nullptr;
    std::mutex mrMapMutex_;
    std::map<uint32_t, std::pair<struct mr_info, MrHandle>> regedMrMap_; // registered MR map
};
}  // namespace hccl
#endif  // HCCL_TYPICAL_MR_MANAGER_H